{% extends 'GessehCoreBundle::layout.html.twig' %}

{% block titlecontent %}Simulation de choix de stage{% endblock %}

{% block content %}
  <h2>Périodes de simulation</h2>
  {% if period_form is not empty %}
    {% form_theme period_form 'GessehCoreBundle:Form:fields.html.twig' %}
    <div>{{ form_errors(period_form) }}</div>
    <form method="post" {{ form_enctype(period_form) }}>
  {% endif %}
  <table>
    <thead>
      <tr>
        <th>Période de stage</th>
        <th>Début des simulations</th>
        <th>Fin des simulations</th>
        <th class="actions">Actions</th>
      </tr>
    </thead>
    <tbody>
      {% for period in periods %}
        {% include period_id == period.id ? 'GessehSimulationBundle:SimulationAdmin:editPeriod.html.twig' : 'GessehSimulationBundle:SimulationAdmin:indexPeriod.html.twig' %}
      {% else %}
        <tr>
          <td colspan=4>Aucune session de simulation à afficher.</td>
        </tr>
      {% endfor %}
      {% if period_form is not empty and period_id is empty %}
        {% include 'GessehSimulationBundle:SimulationAdmin:editPeriod.html.twig' %}
      {% endif %}
    </tbody>
    <tfoot>
      <tr>
        <td>
          <ul>
            <li><a href="{{ path('GSimul_SANewPeriod') }}" title="Ajouter une nouvelle session de simulation">Ajouter</a></li>
          </ul>
        </td>
      </tr>
    </tfoot>
  </table>
  {% if period_form is not empty %}</form>{% endif %}

  <h2>Table de simulation</h2>
  <table>
      <thead>
        <tr>
          <th class="small">Rang</th>
          <th>Étudiant</th>
          <th>Poste</th>
          <th class="small">Vœux</th>
          <th class="small">Reste</th>
          <th class="actions">Actions</th>
        </tr>
      </thead>
      <tbody>
        {% for simulation in simulations %}
          <tr>
            <td class="small">{{ simulation.id }}</td>
            <td>{{ simulation.student.surname }} {{ simulation.student.name }}</td>
            {% if simulation.active %}
              {% if simulation.department %}
                <td>{{ simulation.department }}</td>
              {% else %}
                <td>Aucun choix valide</td>
              {% endif %}
            {% else %}
              <td>Ne participe pas aux simulations</td>
            {% endif %}
            <td class="small">{{ simulation.countWishes }}</td>
            <td class="small">{{ simulation.extra }}</td>
            <td class="actions">
              <ul>
                <li><a href="{{ path('GSimul_SAIndexWish', {'id': simulation.id}) }}" title="Afficher les vœux de l'étudiant {{ simulation.student }}">Vœux</a></li>
              </ul>
            </td>
          <tr>
        {% else %}
          <tr>
            <td colspan=5>La table de simulation n'est pas générée. <a href="{{ path('GSimulation_SADefine') }}" title="Cliquez pour générer la table de simulation">Générer la table</a></td>
          </tr>
        {% endfor %}
      </tbody>
      <tfoot>
        <tr>
          <td class="pagination" colspan=6>{{ knp_pagination_render(simulations) }}</td>
        </tr>
      </tfoot>
    </table>
    {% if simulations is not empty %}
      <div>
        <ul>
          <li><a href="{{ path('GSimulation_SASim') }}" title="Lancer l'algorithme de simulation">Lancer les simulations</a></li>
          <li><a href="{{ path('GSimulation_SAPurge') }}" title="Supprimer la table de simulation (supprime TOUTES les données)" class="confirm">Supprimer la table de simulation</a></li>
          <li><a href="{{ path('GSimulation_SASave') }}" title="Valider les simulation et les enregistrer dans les stages.">Valider les simulations</a></li>
        </ul>
      </div>
    {% endif %}
{% endblock %}

{% block javascripts %}
  {{ parent() }}
  <script src="{{ asset('bundles/gessehcore/js/confirm.js') }}" type="text/javascript"></script>
{% endblock %}
